package com.k.kpp;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.Texts;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;

public class POITLWordTest {
    public static void main(String[] args) throws IOException {
        test();
    }

    public static void test() throws IOException {
        String templatesPath = POITLWordTest.class.getClassLoader().getResource("templates").getPath() + "/a.docx";
        String targetPath = "E:\\test\\poitl\\a-targetc.docx";
        System.out.println("templatesPath:" + templatesPath);
        System.out.println("targetPath:" + targetPath);
        XWPFTemplate template = XWPFTemplate.compile(templatesPath).render(
                new HashMap<String, Object>() {
                    {
                        put("name", "测试");
                        put("author", Texts.of("Liziba").color("000000").create());
                        put("link", Texts.of("百度").link("https://baidu.com").create());
                        put("anchor", Texts.of("anchortxt").anchor("appendix1").create());
                    }
                });
        template.writeAndClose(new FileOutputStream(targetPath));
    }
}
